
//
// 120316 - AH - (Bergen Off. Bibliotek *) Created.
// 120618 - AH - (Huset *) Removed getHttpRequestDef() method: Default
//               implementation from super class is OK here.
// 120727 - AH - (Midtun *) Respond object now array not list.
//

package org.soekrat.server.servlets.account;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.soekrat.server.io.db.Account;
import org.soekrat.server.io.db.SoekratDAO;
import org.soekrat.server.io.db.SoekratDAOFactory;
import org.soekrat.server.servlets.AbstractSoekratHttpServlet;
import org.soekrat.server.servlets.SoekratResponse;

/**
 * <p>
 *   Implements request to get all
 *   {@link Account}s.
 * </p>
 * @author Arne Halvorsen (AH) 
 * @author Laetitia Le Chatton (LLC)
 */
@SuppressWarnings("serial")
public final class GetAccountsHttpServlet extends AbstractSoekratHttpServlet 
{
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public GetAccountsHttpServlet(){}
  
  @Override
  protected void handleRequest(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException 
  {
    SoekratDAO dao=new SoekratDAOFactory().create();
    
    List<Account> accounts=dao.getAccounts();
    
    SoekratResponse r=
      new SoekratResponse(accounts.toArray(Account.EMPTY_ARRAY));
    
    respond(res, r);
  }
  
}
